/************************************************************************
 * SMLib - State Model Library
 * Copyright (C) 2012-2013 Ali Khalili (khalili_DOT_ir_@SIGN_gmail_DOT_com)
 * **********************************************************************
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License (LGPL) published 
 * by the Free Software Foundation; either version 2.1 of the License, or (at your
 * option) any later version. This program is distributed without any
 * warranty. See the GNU Lesser General Public License for more details. 
 * ***********************************************************************
 * File         :     
 * Description  :     
 * Change log   :     
 * To Do        :
 ************************************************************************/
using System;

namespace SMLib.Automata.Moore
{
	/// <summary>
	/// Moore machine emulator.
	/// </summary>
	public class SUL_Emulator_MooreMachine : IBlackBox_MooreMachine
	{
		MooreMachine machine;
		MooreMachine.Moore_State currentState;

		/// <summary>
		/// Initializes a new instance of the <see cref="SMLib.Automata.Moore.SUL_Emulator_MooreMachine"/> class.
		/// </summary>
		/// <param name="machine">Machine.</param>
		public SUL_Emulator_MooreMachine (MooreMachine machine)
		{
			this.machine = machine;
			currentState = this.machine.InitialState;
		}

		#region IBlackBox_MooreMachine implementation

		public void Reset ()
		{
			currentState = this.machine.InitialState;
		}

		public void Step (SMLib.Automata.Base.ISymbol input)
		{
			foreach (MooreMachine.Moore_Transition tr in currentState.Transitions) {
				if (tr.Label.Equals (input)) {
					currentState = tr.Destination;
					return;
				}
			}
			throw new Exception ("Not Enabled!");//NotEnabledException ();
		}

		public SMLib.Automata.Base.ISymbol CurrentOutput {
			get {
				return currentState.Output;
			}
		}

		public SMLib.Automata.Base.Alphabet InputAlphabet {
			get {
				return machine.InputAlphabet;
			}
		}

		#endregion
	}
}

